package mdt.figure;

import java.awt.Color;
import java.awt.Rectangle;

import org.tigris.gef.presentation.Fig;
import org.tigris.gef.presentation.FigCircle;
import org.tigris.gef.presentation.FigEdge;
import org.tigris.gef.presentation.FigNode;

public class FigEdgePort extends FigNode {

  private static final long serialVersionUID = 1L;
  
  private FigCircle bigPort;

  private void initialize() {
      bigPort = new FigCircle(0, 0, 1, 1, Color.black, Color.white);
      addFig(bigPort);
  }

  /**
   * @param owner owning uml element
   * @param bounds ignored
   */
  public FigEdgePort(Object owner, Rectangle bounds) {
      super(owner);
      initialize();
      bigPort.setOwner(owner);
      setBounds(bounds);
  }
  
  /*
   * @see org.tigris.gef.presentation.Fig#hit(java.awt.Rectangle)
   */
  @Override
  public boolean hit(Rectangle r) {
      return false;
  }
  
  @Override
  public Object getOwner() {
if (super.getOwner() != null) {
    return super.getOwner();
}
      Fig group = this;
      while (group != null && !(group instanceof FigEdge)) {
          group = group.getGroup();
      }
      if (group == null) {
          return null;
      } else {
          return group.getOwner();
      }
  }

  /*
   * @see org.tigris.gef.presentation.Fig#classNameAndBounds()
   */
  // USED BY PGML.tee
  @Override
  public String classNameAndBounds() {
      return getClass().getName()
          + "[" + getX() + ", " + getY() + ", "
          + getWidth() + ", " + getHeight() + "]";
  }

  /*
   * @see org.tigris.gef.presentation.FigNode#hitPort(int, int)
   */
  @Override
  public Object hitPort(int x, int y) {
      return null;
  }

  /*
   * @see org.tigris.gef.presentation.FigGroup#hitFig(java.awt.Rectangle)
   */
  @Override
  public Fig hitFig(Rectangle r) {
      return null;
  }

  /*
   * @see org.tigris.gef.presentation.Fig#isSelectable()
   */
  @Override
  public boolean isSelectable() {
      return false;
  }

  /*
   * @see org.tigris.gef.presentation.FigNode#getPortFig(java.lang.Object)
   */
  public Fig getPortFig(Object port) {
      return bigPort;
  }
}